﻿namespace WMS6.Web.OrderManagement
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.LoginServiceRef;
    using WMS6.Web.OrderDetailMgtServiceRef;

    public class PurchaseOrderDetail : BasePage
    {
        protected HtmlAnchor A1;
        protected HtmlAnchor ASkuID;
        protected Button btnCancel;
        protected Button btnPriceChanges;
        protected Button btnSave;
        protected Button btnSaveContinue;
        protected CheckBox chbIsSalePromption;
        protected CheckBox chkQcAutoAdjust;
        protected CheckBox chkQcRequired;
        protected DropDownList ddlStatus;
        protected DropDownList ddlUomID;
        protected HtmlForm F3013;
        protected HtmlInputHidden hdnFormart;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnPageQty;
        protected HtmlInputHidden hdnPageType;
        protected HtmlInputHidden hdnpoID;
        protected HtmlInputHidden hdnTotalCube;
        protected HtmlInputHidden hdnTotalGrossWeight;
        protected HtmlInputHidden hdnTotalNetWeight;
        protected HtmlInputHidden hdnTotalPrice;
        protected HtmlInputHidden hdnUnitPrice;
        protected HtmlInputHidden hdnUomValue;
        protected HtmlInputHidden hdnVendorID;
        protected ImageButton imgBtnQty;
        protected Label lblAllocateRuleDetail;
        protected Label lblAltSkuID;
        protected Label lblColor;
        protected Label lblCostPrice;
        protected Label lblCube;
        protected Label lblGrossWgt;
        protected Label lblHeight;
        protected Label lblLength;
        protected Label lbllineID;
        protected Label lblMsg;
        protected Label lblNetPrice;
        protected Label lblNetWgt;
        protected Label lblOrderedQty;
        protected Label lblOwnerID;
        protected Label lblPakcID;
        protected Label lblpoID;
        protected Label lblQty;
        protected Label lblRceivedQty;
        protected Label lblRejectedQty;
        protected Label lblRemark;
        protected Label lblReorderPoint;
        protected Label lblReorderQty;
        protected Label lblShelfLifeCodeType;
        protected Label lblSize;
        protected Label lblSkuDesc;
        protected Label lblSkuID;
        protected Label lblSkuStyle;
        protected Label lblStatus;
        protected Label lblTareWgt;
        protected Label lblTotalCube;
        protected Label lblTotalGrossWeight;
        protected Label lblTotalNetWeight;
        protected Label lblTotalPrice;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf4;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUdf9;
        protected Label lblUnitPrice;
        protected Label lblUomID;
        protected Label lblWight;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAltSkuID;
        protected TextBox txtColor;
        protected TextBox txtCostPrice;
        protected TextBox txtCrossWgt;
        protected TextBox txtCube;
        protected TextBox txtHeight;
        protected TextBox txtInvQty;
        protected TextBox txtLength;
        protected TextBox txtlineID;
        protected TextBox txtNetPrice;
        protected TextBox txtNetWgt;
        protected TextBox txtOrderedQty;
        protected TextBox txtOwnerID;
        protected TextBox txtPackID;
        protected TextBox txtpoID;
        protected TextBox txtRceivedQty;
        protected TextBox txtRejectedQty;
        protected TextBox txtRemark;
        protected TextBox txtReorderPoint;
        protected TextBox txtReorderQty;
        protected TextBox txtShelfLifeOnReceiving;
        protected TextBox txtSize;
        protected TextBox txtSkuDesc;
        protected TextBox txtSkuID;
        protected TextBox txtSkuStyle;
        protected TextBox txtTareWgt;
        protected TextBox txtTotalCube;
        protected TextBox txtTotalGrossWeight;
        protected TextBox txtTotalNetWeight;
        protected TextBox txtTotalPrice;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected TextBox txtUnitPrice;
        protected HtmlInputText txtUpdateUnitPrice;
        protected TextBox txtWight;
        protected UpdatePanel up1;
        protected HtmlInputHidden UpdateUnitPrice;

        private void BindData2UomList(string packID)
        {
            try
            {
                List<WMS6.Web.CommonMethodServiceRef.UomList> uomList = CommoneMethodServiceClientProxy.GetInstance().GetUomListByPackID(packID);
                if ((uomList != null) && (uomList.Count > 0))
                {
                    base.BindUomList2DDL(this.ddlUomID, uomList);
                    this.ViewState["UOMLIST"] = uomList;
                    this.CalcSkuWgtCube();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_020") + ex.Message;
                this.txtPackID.Focus();
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("PurchaseOrder.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnpoID.Value.Trim())), false);
        }

        protected void btnPriceChanges_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
            {
                this.lblMsg.Text = "新建状态,无需修改价格,请直接修改后保存!";
            }
            else
            {
                try
                {
                    if (!string.IsNullOrEmpty(this.UpdateUnitPrice.Value))
                    {
                        float price = float.Parse(this.UpdateUnitPrice.Value);
                        float totalprice = (float.Parse(this.UpdateUnitPrice.Value) * float.Parse(this.hdnUomValue.Value)) * float.Parse(this.txtOrderedQty.Text);
                        string strtemp = OrderDetailMgtServiceClientProxy.GetInstance().PurchaseOrderDetailPriceChanges(this.txtpoID.Text, this.txtlineID.Text, price, totalprice);
                        if (string.IsNullOrEmpty(strtemp))
                        {
                            this.lblMsg.Text = "价格修改成功!";
                            this.txtUnitPrice.Text = base.GetPreferenceDigit(this.UpdateUnitPrice.Value);
                            this.txtTotalPrice.Text = base.GetPreferenceDigit(totalprice);
                        }
                        else
                        {
                            this.lblMsg.Text = strtemp;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = "价格修改失败:" + ex.Message;
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            decimal decOut = 0.0M;
            double douOut = 0.0;
            float floatTemp = 0f;
            if (this.ddlStatus.SelectedValue.ToUpper() == "RECEIVEDCOMPLETE")
            {
                this.lblMsg.Text = "该明细已经收货完成,无法保存!";
            }
            else if (string.IsNullOrEmpty(this.txtSkuID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_015");
                this.txtSkuID.Focus();
            }
            else if (string.IsNullOrEmpty(this.txtOrderedQty.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_016");
                this.txtOrderedQty.Focus();
            }
            else if (string.IsNullOrEmpty(this.txtPackID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_017");
                this.txtPackID.Focus();
            }
            else if (string.IsNullOrEmpty(this.ddlUomID.SelectedValue))
            {
                this.lblMsg.Text = "包装" + this.txtPackID.Text + " 未找到对应的计量单位！";
            }
            else
            {
                bool success = false;
                try
                {
                    PurchaseOrderDetailInfo purchaseOrderDetailInfo = new PurchaseOrderDetailInfo {
                        PoID = this.txtpoID.Text.Trim(),
                        LineID = int.Parse(this.txtlineID.Text.Trim()),
                        Status = this.ddlStatus.SelectedValue
                    };
                    if (float.TryParse(this.txtUnitPrice.Text.Trim(), out floatTemp))
                    {
                        purchaseOrderDetailInfo.UnitPrice = float.Parse(this.txtUnitPrice.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.UnitPrice = floatTemp;
                    }
                    if (double.TryParse(this.txtTotalPrice.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalPrice = double.Parse(this.txtTotalPrice.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalPrice = douOut;
                    }
                    if (decimal.TryParse(this.txtRejectedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.ReceivedQty = decimal.Parse(this.txtRejectedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.ReceivedQty = decOut;
                    }
                    purchaseOrderDetailInfo.OwnerID = this.txtOwnerID.Text.Trim();
                    purchaseOrderDetailInfo.SkuID = this.txtSkuID.Text.Trim();
                    purchaseOrderDetailInfo.SkuDesc = this.txtSkuDesc.Text.Trim();
                    purchaseOrderDetailInfo.AltSkuID = this.txtAltSkuID.Text.Trim();
                    if (decimal.TryParse(this.txtOrderedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.OrderedQty = decimal.Parse(this.txtOrderedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.OrderedQty = decOut;
                    }
                    purchaseOrderDetailInfo.PackID = this.txtPackID.Text.Trim();
                    purchaseOrderDetailInfo.UomID = this.ddlUomID.SelectedValue;
                    if (double.TryParse(this.txtTotalGrossWeight.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalGrossWeight = double.Parse(this.txtTotalGrossWeight.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalGrossWeight = douOut;
                    }
                    if (double.TryParse(this.txtTotalNetWeight.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalNetWeight = double.Parse(this.txtTotalNetWeight.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalNetWeight = douOut;
                    }
                    if (double.TryParse(this.txtTotalPrice.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalPrice = double.Parse(this.txtTotalPrice.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalPrice = douOut;
                    }
                    if (decimal.TryParse(this.txtRejectedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.RejectedQty = decimal.Parse(this.txtRejectedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.RejectedQty = decOut;
                    }
                    if (double.TryParse(this.txtTotalCube.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalCube = double.Parse(this.txtTotalCube.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalCube = douOut;
                    }
                    if (!string.IsNullOrEmpty(this.txtRceivedQty.Text))
                    {
                        purchaseOrderDetailInfo.ReceivedQty = decimal.Parse(this.txtRceivedQty.Text);
                    }
                    purchaseOrderDetailInfo.QcAutoAdjust = this.chkQcAutoAdjust.Checked ? "Y" : "N";
                    purchaseOrderDetailInfo.QcRequired = this.chkQcRequired.Checked ? "Y" : "N";
                    purchaseOrderDetailInfo.Udf1 = this.txtUdf1.Text.Trim();
                    purchaseOrderDetailInfo.Udf2 = this.txtUdf2.Text.Trim();
                    purchaseOrderDetailInfo.Udf3 = this.txtUdf3.Text.Trim();
                    purchaseOrderDetailInfo.Udf4 = this.txtUdf4.Text.Trim();
                    purchaseOrderDetailInfo.Udf5 = this.txtUdf5.Text.Trim();
                    purchaseOrderDetailInfo.Udf6 = this.txtUdf6.Text.Trim();
                    purchaseOrderDetailInfo.Udf7 = this.txtUdf7.Text.Trim();
                    purchaseOrderDetailInfo.Udf8 = this.txtUdf8.Text.Trim();
                    purchaseOrderDetailInfo.Udf9 = this.txtUdf9.Text.Trim();
                    purchaseOrderDetailInfo.Udf10 = this.txtUdf10.Text.Trim();
                    purchaseOrderDetailInfo.Remark = this.txtRemark.Text.Trim();
                    purchaseOrderDetailInfo.CreatedBy = base.UserInfo.UserID;
                    if ((this.ViewState["Update"] != null) && (this.ViewState["Update"].ToString() == "1"))
                    {
                        purchaseOrderDetailInfo.UpdatedBy = base.UserInfo.UserID;
                        if (!string.IsNullOrEmpty(OrderDetailMgtServiceClientProxy.GetInstance().UpdatePurchaseOrderDetailInfo(purchaseOrderDetailInfo)))
                        {
                            success = true;
                        }
                    }
                    else if (!string.IsNullOrEmpty(OrderDetailMgtServiceClientProxy.GetInstance().InsertPurchaseOrderDetailInfo(purchaseOrderDetailInfo)))
                    {
                        success = true;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F3100_018") + ex.Message;
                    return;
                }
                if (success)
                {
                    if ((this.ViewState["Update"] != null) && (this.ViewState["Update"].ToString() == "1"))
                    {
                        base.Response.Redirect(string.Format("PurchaseOrder.aspx?from=list&detail=1&ID={0}", base.UrlEncode(this.txtpoID.Text.Trim())), false);
                    }
                    else
                    {
                        base.Response.Redirect(string.Format("PurchaseOrder.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnpoID.Value.Trim())), false);
                    }
                }
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            decimal decOut = 0.0M;
            double douOut = 0.0;
            float floatTemp = 0f;
            if (string.IsNullOrEmpty(this.txtSkuID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_015");
                this.txtSkuID.Focus();
            }
            else if (string.IsNullOrEmpty(this.txtOrderedQty.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_016");
                this.txtOrderedQty.Focus();
            }
            else if (string.IsNullOrEmpty(this.txtPackID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F3100_017");
                this.txtPackID.Focus();
            }
            else if (string.IsNullOrEmpty(this.ddlUomID.SelectedValue))
            {
                this.lblMsg.Text = "包装" + this.txtPackID.Text + " 未找到对应的计量单位！";
            }
            else
            {
                bool success = false;
                try
                {
                    PurchaseOrderDetailInfo purchaseOrderDetailInfo = new PurchaseOrderDetailInfo {
                        PoID = this.txtpoID.Text.Trim(),
                        LineID = int.Parse(this.txtlineID.Text.Trim()),
                        Status = this.ddlStatus.SelectedValue
                    };
                    if (decimal.TryParse(this.txtRejectedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.ReceivedQty = decimal.Parse(this.txtRejectedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.ReceivedQty = decOut;
                    }
                    purchaseOrderDetailInfo.OwnerID = this.txtOwnerID.Text.Trim();
                    purchaseOrderDetailInfo.SkuID = this.txtSkuID.Text.Trim();
                    purchaseOrderDetailInfo.SkuDesc = this.txtSkuDesc.Text.Trim();
                    purchaseOrderDetailInfo.AltSkuID = this.txtAltSkuID.Text.Trim();
                    if (decimal.TryParse(this.txtOrderedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.OrderedQty = decimal.Parse(this.txtOrderedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.OrderedQty = decOut;
                    }
                    purchaseOrderDetailInfo.PackID = this.txtPackID.Text.Trim();
                    purchaseOrderDetailInfo.UomID = this.ddlUomID.SelectedValue;
                    if (double.TryParse(this.txtTotalGrossWeight.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalGrossWeight = double.Parse(this.txtTotalGrossWeight.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalGrossWeight = douOut;
                    }
                    if (double.TryParse(this.txtTotalNetWeight.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalNetWeight = double.Parse(this.txtTotalNetWeight.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalNetWeight = douOut;
                    }
                    if (float.TryParse(this.txtUnitPrice.Text.Trim(), out floatTemp))
                    {
                        purchaseOrderDetailInfo.UnitPrice = float.Parse(this.txtUnitPrice.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.UnitPrice = floatTemp;
                    }
                    if (double.TryParse(this.txtTotalPrice.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalPrice = double.Parse(this.txtTotalPrice.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalPrice = douOut;
                    }
                    if (decimal.TryParse(this.txtRejectedQty.Text.Trim(), out decOut))
                    {
                        purchaseOrderDetailInfo.RejectedQty = decimal.Parse(this.txtRejectedQty.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.RejectedQty = decOut;
                    }
                    if (double.TryParse(this.txtTotalCube.Text.Trim(), out douOut))
                    {
                        purchaseOrderDetailInfo.TotalCube = double.Parse(this.txtTotalCube.Text.Trim());
                    }
                    else
                    {
                        purchaseOrderDetailInfo.TotalCube = douOut;
                    }
                    purchaseOrderDetailInfo.QcAutoAdjust = this.chkQcAutoAdjust.Checked ? "Y" : "N";
                    purchaseOrderDetailInfo.QcRequired = this.chkQcRequired.Checked ? "Y" : "N";
                    purchaseOrderDetailInfo.Udf1 = this.txtUdf1.Text.Trim();
                    purchaseOrderDetailInfo.Udf2 = this.txtUdf2.Text.Trim();
                    purchaseOrderDetailInfo.Udf3 = this.txtUdf3.Text.Trim();
                    purchaseOrderDetailInfo.Udf4 = this.txtUdf4.Text.Trim();
                    purchaseOrderDetailInfo.Udf5 = this.txtUdf5.Text.Trim();
                    purchaseOrderDetailInfo.Udf6 = this.txtUdf6.Text.Trim();
                    purchaseOrderDetailInfo.Udf7 = this.txtUdf7.Text.Trim();
                    purchaseOrderDetailInfo.Udf8 = this.txtUdf8.Text.Trim();
                    purchaseOrderDetailInfo.Udf9 = this.txtUdf9.Text.Trim();
                    purchaseOrderDetailInfo.Udf10 = this.txtUdf10.Text.Trim();
                    purchaseOrderDetailInfo.Remark = this.txtRemark.Text.Trim();
                    purchaseOrderDetailInfo.CreatedBy = base.UserInfo.UserID;
                    if (!string.IsNullOrEmpty(OrderDetailMgtServiceClientProxy.GetInstance().InsertPurchaseOrderDetailInfo(purchaseOrderDetailInfo)))
                    {
                        success = true;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F3100_018") + ex.Message;
                    return;
                }
                if (success)
                {
                    this.lblMsg.Text = this.txtlineID.Text + base.GetGlobalMsgResource("C004");
                    this.txtlineID.Text = (int.Parse(this.txtlineID.Text.Trim()) + 10).ToString();
                    this.txtRejectedQty.Text = "";
                    this.txtSkuID.Text = "";
                    this.txtSkuDesc.Text = "";
                    this.txtOrderedQty.Text = "";
                    this.txtAltSkuID.Text = "";
                    this.txtPackID.Text = "";
                    if (this.ddlUomID.Items.Count > 0)
                    {
                        this.ddlUomID.SelectedValue = this.ddlUomID.Items[0].Value;
                    }
                    this.txtTotalGrossWeight.Text = "";
                    this.txtTotalNetWeight.Text = "";
                    this.txtTotalPrice.Text = "";
                    this.txtRejectedQty.Text = "";
                    this.txtTotalCube.Text = "";
                    this.txtUdf1.Text = "";
                    this.txtUdf2.Text = "";
                    this.txtUdf3.Text = "";
                    this.txtUdf4.Text = "";
                    this.txtUdf5.Text = "";
                    this.txtUdf6.Text = "";
                    this.txtUdf7.Text = "";
                    this.txtUdf8.Text = "";
                    this.txtUdf9.Text = "";
                    this.txtUdf10.Text = "";
                    this.txtRemark.Text = "";
                    this.txtUnitPrice.Text = "";
                    this.hdnUnitPrice.Value = "";
                }
                this.hdnPageQty.Value = "0";
                this.CountrolsClick();
            }
        }

        private void CalcSkuWgtCube()
        {
            List<WMS6.Web.CommonMethodServiceRef.UomList> uomList = this.ViewState["UOMLIST"] as List<WMS6.Web.CommonMethodServiceRef.UomList>;
            float uomQty = base.GetUomQtyByUomList(this.ddlUomID.SelectedValue, uomList);
            this.hdnUomValue.Value = uomQty.ToString();
            if (uomQty > 0f)
            {
                float cube = string.IsNullOrEmpty(this.hdnTotalCube.Value.Trim()) ? 0f : float.Parse(this.hdnTotalCube.Value.Trim());
                float grossWgt = string.IsNullOrEmpty(this.hdnTotalGrossWeight.Value.Trim()) ? 0f : float.Parse(this.hdnTotalGrossWeight.Value.Trim());
                float netWgt = string.IsNullOrEmpty(this.hdnTotalNetWeight.Value.Trim()) ? 0f : float.Parse(this.hdnTotalNetWeight.Value.Trim());
                float price = string.IsNullOrEmpty(this.hdnTotalPrice.Value.Trim()) ? 0f : float.Parse(this.hdnTotalPrice.Value.Trim());
                float orderedQty = string.IsNullOrEmpty(this.txtOrderedQty.Text.Trim()) ? 0f : float.Parse(this.txtOrderedQty.Text.Trim());
                this.txtTotalCube.Text = base.GetPreferenceDigit((float) ((cube * uomQty) * orderedQty));
                this.txtTotalGrossWeight.Text = base.GetPreferenceDigit((float) ((grossWgt * uomQty) * orderedQty));
                this.txtTotalNetWeight.Text = base.GetPreferenceDigit((float) ((netWgt * uomQty) * orderedQty));
                this.txtTotalPrice.Text = base.GetPreferenceDigit((float) ((price * uomQty) * orderedQty));
            }
            else
            {
                this.txtTotalCube.Text = "";
                this.txtTotalGrossWeight.Text = "";
                this.txtTotalNetWeight.Text = "";
                this.txtTotalPrice.Text = "";
            }
        }

        private void CountrolsClick()
        {
            this.txtpoID.Attributes.Add("RecordValue", "0");
            this.txtpoID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtpoID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtlineID.Attributes.Add("RecordValue", "0");
            this.txtlineID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtlineID.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlStatus.Attributes.Add("RecordValue", "0");
            this.ddlStatus.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlStatus.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwnerID.Attributes.Add("RecordValue", "0");
            this.txtOwnerID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwnerID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtSkuID.Attributes.Add("RecordValue", "0");
            this.txtSkuID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtSkuID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtSkuDesc.Attributes.Add("RecordValue", "0");
            this.txtSkuDesc.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtSkuDesc.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPackID.Attributes.Add("RecordValue", "0");
            this.txtPackID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPackID.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlUomID.Attributes.Add("RecordValue", "0");
            if (this.ddlUomID.SelectedItem == null)
            {
                this.ddlUomID.Attributes.Add("onfocusout", "RecordPageValue('',this, 'hdnPageQty'); return true; ");
            }
            else
            {
                this.ddlUomID.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlUomID.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            }
            this.txtOrderedQty.Attributes.Add("RecordValue", "0");
            this.txtOrderedQty.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOrderedQty.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtRceivedQty.Attributes.Add("RecordValue", "0");
            this.txtRceivedQty.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtRceivedQty.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtRejectedQty.Attributes.Add("RecordValue", "0");
            this.txtRejectedQty.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtRejectedQty.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtTotalGrossWeight.Attributes.Add("RecordValue", "0");
            this.txtTotalGrossWeight.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtTotalGrossWeight.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtTotalNetWeight.Attributes.Add("RecordValue", "0");
            this.txtTotalNetWeight.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtTotalNetWeight.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtTotalPrice.Attributes.Add("RecordValue", "0");
            this.txtTotalPrice.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtTotalPrice.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtTotalCube.Attributes.Add("RecordValue", "0");
            this.txtTotalCube.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtTotalCube.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtRemark.Attributes.Add("RecordValue", "0");
            this.txtRemark.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtRemark.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf1.Attributes.Add("RecordValue", "0");
            this.txtUdf1.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf1.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf2.Attributes.Add("RecordValue", "0");
            this.txtUdf2.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf2.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf3.Attributes.Add("RecordValue", "0");
            this.txtUdf3.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf3.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf4.Attributes.Add("RecordValue", "0");
            this.txtUdf4.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf4.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf5.Attributes.Add("RecordValue", "0");
            this.txtUdf5.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf5.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf6.Attributes.Add("RecordValue", "0");
            this.txtUdf6.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf6.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf7.Attributes.Add("RecordValue", "0");
            this.txtUdf7.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf7.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf8.Attributes.Add("RecordValue", "0");
            this.txtUdf8.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf8.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf9.Attributes.Add("RecordValue", "0");
            this.txtUdf9.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf9.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf10.Attributes.Add("RecordValue", "0");
            this.txtUdf10.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf10.Text + "',this, 'hdnPageQty'); return true; ");
        }

        protected void ddlUomID_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CalcSkuWgtCube();
        }

        protected void imgBtnQty_Click(object sender, ImageClickEventArgs e)
        {
            if (!(string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()) || string.IsNullOrEmpty(this.txtSkuID.Text.Trim())))
            {
                this.txtInvQty.Text = CommoneMethodServiceClientProxy.GetInstance().GetAvailableQty(this.txtOwnerID.Text.Trim(), this.txtSkuID.Text.Trim()).ToString();
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlStatus, "PoStatus");
            this.txtlineID.Enabled = false;
            this.txtLength.Enabled = false;
            this.txtCube.Enabled = false;
            this.txtSize.Enabled = false;
            this.txtCostPrice.Enabled = false;
            this.txtWight.Enabled = false;
            this.txtNetWgt.Enabled = false;
            this.txtColor.Enabled = false;
            this.txtNetPrice.Enabled = false;
            this.txtHeight.Enabled = false;
            this.txtCrossWgt.Enabled = false;
            this.txtSkuStyle.Enabled = false;
            this.chbIsSalePromption.Enabled = false;
            this.txtTareWgt.Enabled = false;
            this.txtShelfLifeOnReceiving.Enabled = false;
            this.txtInvQty.Enabled = false;
            this.txtReorderQty.Enabled = false;
            this.txtReorderPoint.Enabled = false;
            if (base.Request.QueryString["ID"] != null)
            {
                string poID = base.Request.QueryString["ID"];
                this.txtpoID.Text = poID;
                this.txtpoID.Enabled = false;
                this.hdnpoID.Value = poID;
            }
            if (base.Request.QueryString["from"] != null)
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (base.Request.QueryString["SeqNO"] != null)
            {
                string LineID = base.Request.QueryString["SeqNO"];
                this.txtlineID.Text = LineID;
            }
            if (base.Request.QueryString["OwnerID"] != null)
            {
                this.txtOwnerID.Text = base.Request.QueryString["OwnerID"];
                this.txtOwnerID.Enabled = false;
            }
            if (base.Request.QueryString["VendorID"] != null)
            {
                this.hdnVendorID.Value = base.Request.QueryString["VendorID"].ToString();
            }
            if ((base.Request.QueryString["ID"] != null) && (base.Request.QueryString["lineID"] != null))
            {
                this.ViewState["Update"] = "1";
                this.SetVauleByIDAndLineID(base.Request.QueryString["ID"], base.Request.QueryString["lineID"]);
                this.btnSaveContinue.Enabled = false;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
                PreferenceInfo preferenceInfo = base.UserInfo.Preference;
                this.hdnFormart.Value = preferenceInfo.Digits_No;
                this.CountrolsClick();
            }
        }

        private void SetVauleByIDAndLineID(string ID, string lineID)
        {
            PurchaseOrderDetailInfo purchaseOrder = OrderDetailMgtServiceClientProxy.GetInstance().GetPurchaseOrderDetailInfoBypoIDAndLineID(ID, lineID);
            if (purchaseOrder != null)
            {
                this.txtpoID.Text = purchaseOrder.PoID;
                this.txtlineID.Text = purchaseOrder.LineID.ToString();
                this.ddlStatus.SelectedValue = purchaseOrder.Status;
                if (purchaseOrder.Status.ToUpper() != "NEW")
                {
                    this.txtUnitPrice.Enabled = false;
                }
                this.txtOwnerID.Text = purchaseOrder.OwnerID;
                this.txtOwnerID.Enabled = false;
                this.txtSkuID.Text = purchaseOrder.SkuID;
                this.txtSkuID_TextChanged(null, null);
                this.txtSkuDesc.Text = purchaseOrder.SkuDesc;
                this.txtPackID.Text = purchaseOrder.PackID;
                this.BindData2UomList(this.txtPackID.Text.Trim());
                this.txtAltSkuID.Text = purchaseOrder.AltSkuID;
                this.ddlUomID.SelectedValue = purchaseOrder.UomID;
                List<WMS6.Web.CommonMethodServiceRef.UomList> uomList = this.ViewState["UOMLIST"] as List<WMS6.Web.CommonMethodServiceRef.UomList>;
                float uomQty = base.GetUomQtyByUomList(this.ddlUomID.SelectedValue, uomList);
                this.hdnUomValue.Value = uomQty.ToString();
                this.txtOrderedQty.Text = base.GetPreferenceDigit(purchaseOrder.OrderedQty);
                this.txtRceivedQty.Text = base.GetPreferenceDigit(purchaseOrder.ReceivedQty);
                this.txtRejectedQty.Text = base.GetPreferenceDigit(purchaseOrder.RejectedQty);
                this.txtTotalGrossWeight.Text = base.GetPreferenceDigit(purchaseOrder.TotalGrossWeight);
                this.txtTotalNetWeight.Text = base.GetPreferenceDigit(purchaseOrder.TotalNetWeight);
                this.txtTotalPrice.Text = base.GetPreferenceDigit(purchaseOrder.TotalPrice);
                this.txtTotalCube.Text = base.GetPreferenceDigit(purchaseOrder.TotalCube);
                this.txtUnitPrice.Text = base.GetPreferenceDigit(purchaseOrder.UnitPrice);
                this.hdnUnitPrice.Value = base.GetPreferenceDigit(purchaseOrder.UnitPrice);
                double CS00002 = purchaseOrder.TotalGrossWeight / ((double) (Convert.ToSingle(purchaseOrder.OrderedQty) * uomQty));
                this.hdnTotalGrossWeight.Value = CS00002.ToString();
                CS00002 = purchaseOrder.TotalNetWeight / ((double) (Convert.ToSingle(purchaseOrder.OrderedQty) * uomQty));
                this.hdnTotalNetWeight.Value = CS00002.ToString();
                CS00002 = purchaseOrder.TotalPrice / ((double) (Convert.ToSingle(purchaseOrder.OrderedQty) * uomQty));
                this.hdnTotalPrice.Value = CS00002.ToString();
                this.hdnTotalCube.Value = (purchaseOrder.TotalCube / ((double) (Convert.ToSingle(purchaseOrder.OrderedQty) * uomQty))).ToString();
                this.txtUdf1.Text = purchaseOrder.Udf1;
                this.txtUdf2.Text = purchaseOrder.Udf2;
                this.txtUdf3.Text = purchaseOrder.Udf3;
                this.txtUdf4.Text = purchaseOrder.Udf4;
                this.txtUdf5.Text = purchaseOrder.Udf5;
                this.txtUdf6.Text = purchaseOrder.Udf6;
                this.txtUdf7.Text = purchaseOrder.Udf7;
                this.txtUdf8.Text = purchaseOrder.Udf8;
                this.txtUdf9.Text = purchaseOrder.Udf9;
                this.txtUdf10.Text = purchaseOrder.Udf10;
                this.txtRemark.Text = purchaseOrder.Remark;
                this.chkQcAutoAdjust.Checked = purchaseOrder.QcAutoAdjust == "Y";
                this.chkQcRequired.Checked = purchaseOrder.QcRequired == "Y";
                bool isPSupervisor = false;
                if ((base.UserInfo.UserRoleInfos != null) && (base.UserInfo.UserRoleInfos.Count > 0))
                {
                    for (int n = 0; base.UserInfo.UserRoleInfos.Count > n; n++)
                    {
                        if (base.UserInfo.UserRoleInfos[n].RoleID == "PSupervisor")
                        {
                            isPSupervisor = true;
                            break;
                        }
                    }
                }
                if (!isPSupervisor && (base.UserInfo.UserID != purchaseOrder.CreatedBy))
                {
                    this.btnSave.Enabled = false;
                }
            }
        }

        protected void txtPackID_TextChanged(object sender, EventArgs e)
        {
            this.BindData2UomList(this.txtPackID.Text.Trim());
            this.hdnPageType.Value = "0";
        }

        protected void txtSkuID_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.lblMsg.Text.Trim()))
            {
                this.lblMsg.Text = "";
            }
            try
            {
                string skuID = this.txtSkuID.Text.Trim();
                if (string.IsNullOrEmpty(skuID))
                {
                    this.txtSkuDesc.Text = "";
                    this.txtPackID.Text = "";
                    this.txtTotalGrossWeight.Text = "";
                    this.txtTotalNetWeight.Text = "";
                    this.txtTotalPrice.Text = "";
                    this.txtTotalCube.Text = "";
                    this.hdnTotalGrossWeight.Value = "";
                    this.hdnTotalNetWeight.Value = "";
                    this.hdnTotalPrice.Value = "";
                    this.hdnTotalCube.Value = "";
                    this.hdnUnitPrice.Value = "";
                    this.txtUnitPrice.Text = "";
                    this.ddlUomID.Items.Clear();
                }
                else
                {
                    SkuInfo skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.txtOwnerID.Text.Trim(), skuID, "", "SKU") as SkuInfo;
                    if ((((skuInfo != null) && !string.IsNullOrEmpty(skuInfo.SkuID)) && !string.IsNullOrEmpty(skuInfo.OwnerID)) && (skuInfo.IsActive == "Y"))
                    {
                        this.txtSkuDesc.Text = skuInfo.Descr;
                        this.txtPackID.Text = skuInfo.PackID;
                        this.BindData2UomList(this.txtPackID.Text.Trim());
                        this.txtTotalGrossWeight.Text = base.GetPreferenceDigit(skuInfo.GrossWgt);
                        this.txtTotalNetWeight.Text = base.GetPreferenceDigit(skuInfo.NetWgt);
                        this.txtTotalPrice.Text = base.GetPreferenceDigit(skuInfo.NetPrice);
                        this.txtTotalCube.Text = base.GetPreferenceDigit(skuInfo.Cube);
                        this.hdnTotalGrossWeight.Value = this.txtTotalGrossWeight.Text;
                        this.hdnTotalNetWeight.Value = this.txtTotalNetWeight.Text;
                        this.hdnTotalPrice.Value = this.txtTotalPrice.Text;
                        this.hdnTotalCube.Value = this.txtTotalCube.Text;
                        this.BindData2UomList(this.txtPackID.Text.Trim());
                        this.txtOrderedQty.Focus();
                        this.hdnUnitPrice.Value = base.GetPreferenceDigit(skuInfo.CostPrice.ToString());
                        this.txtUnitPrice.Text = base.GetPreferenceDigit(skuInfo.CostPrice.ToString());
                        if (!string.IsNullOrEmpty(this.txtOrderedQty.Text.Trim()))
                        {
                            this.txtTotalPrice.Text = base.GetPreferenceDigit((float.Parse(this.txtUnitPrice.Text.Trim()) * float.Parse(this.txtOrderedQty.Text.Trim())).ToString());
                        }
                        this.txtLength.Text = base.GetPreferenceDigit(skuInfo.Length);
                        this.txtWight.Text = base.GetPreferenceDigit(skuInfo.Width);
                        this.txtHeight.Text = base.GetPreferenceDigit(skuInfo.Height);
                        this.txtCube.Text = base.GetPreferenceDigit(skuInfo.Cube);
                        this.txtSize.Text = base.GetPreferenceDigit(skuInfo.SkuSize);
                        this.txtCostPrice.Text = base.GetPreferenceDigit(skuInfo.CostPrice);
                        this.txtNetWgt.Text = base.GetPreferenceDigit(skuInfo.NetWgt);
                        this.txtColor.Text = skuInfo.SkuColor;
                        this.txtNetPrice.Text = base.GetPreferenceDigit(skuInfo.NetPrice);
                        this.txtCrossWgt.Text = base.GetPreferenceDigit(skuInfo.GrossWgt);
                        this.txtSkuStyle.Text = skuInfo.SkuStyle;
                        this.chbIsSalePromption.Checked = skuInfo.IsSalePromption == "Y";
                        this.txtTareWgt.Text = base.GetPreferenceDigit(skuInfo.TareWgt);
                        this.txtShelfLifeOnReceiving.Text = skuInfo.ShelfLifeOnReceiving.ToString();
                        this.txtReorderQty.Text = base.GetPreferenceDigit(skuInfo.ReorderQty);
                        this.txtReorderPoint.Text = skuInfo.Udf4;
                    }
                    else
                    {
                        this.txtSkuDesc.Text = "";
                        this.txtPackID.Text = "";
                        this.ddlUomID.Items.Clear();
                        this.txtTotalGrossWeight.Text = base.GetPreferenceDigit(0);
                        this.txtTotalNetWeight.Text = base.GetPreferenceDigit(0);
                        this.txtTotalPrice.Text = base.GetPreferenceDigit(0);
                        this.txtTotalCube.Text = base.GetPreferenceDigit(0);
                        this.hdnTotalGrossWeight.Value = base.GetPreferenceDigit(0);
                        this.hdnTotalNetWeight.Value = "";
                        this.hdnTotalPrice.Value = "";
                        this.hdnTotalCube.Value = "";
                        this.hdnUnitPrice.Value = "";
                        this.txtUnitPrice.Text = base.GetPreferenceDigit(0);
                        this.txtLength.Text = base.GetPreferenceDigit(0);
                        this.txtWight.Text = base.GetPreferenceDigit(0);
                        this.txtHeight.Text = base.GetPreferenceDigit(0);
                        this.txtCube.Text = base.GetPreferenceDigit(0);
                        this.txtSize.Text = base.GetPreferenceDigit(0);
                        this.txtCostPrice.Text = base.GetPreferenceDigit(0);
                        this.txtNetWgt.Text = base.GetPreferenceDigit(0);
                        this.txtColor.Text = "";
                        this.txtNetPrice.Text = base.GetPreferenceDigit(0);
                        this.txtCrossWgt.Text = base.GetPreferenceDigit(0);
                        this.txtSkuStyle.Text = "";
                        this.txtTareWgt.Text = base.GetPreferenceDigit(0);
                        this.txtShelfLifeOnReceiving.Text = "";
                        this.txtReorderQty.Text = base.GetPreferenceDigit(0);
                        this.txtReorderPoint.Text = "";
                        this.lblMsg.Text = base.GetGlobalMsgResource("F3100_019");
                        this.txtSkuID.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.txtSkuID.Focus();
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>CloseSearch();false;</script>", false);
            this.hdnPageType.Value = "0";
        }

        protected void txtUnitPrice_TextChanged(object sender, EventArgs e)
        {
            float floatTemp = 0f;
            if (float.TryParse(this.txtOrderedQty.Text.Trim(), out floatTemp) && float.TryParse(this.txtUnitPrice.Text.Trim(), out floatTemp))
            {
                this.txtTotalPrice.Text = (float.Parse(this.txtOrderedQty.Text.Trim()) * float.Parse(this.txtUnitPrice.Text.Trim())).ToString();
            }
            else
            {
                this.txtTotalPrice.Text = "0";
            }
            this.hdnUnitPrice.Value = this.txtUnitPrice.Text.Trim();
        }
    }
}

